package org.neptune.web.controller;

import org.neptune.common.response.ResponseBean;
import org.neptune.service.redis.RedisRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lwl
 * @date 2019/8/6 14:43
 */
@RestController
@RequestMapping("/redisTest")
public class RedisTestController {

	private static final Logger logger = LoggerFactory.getLogger(RedisTestController.class);

	@Autowired
	private RedisRepository redisRepository;

	@RequestMapping("/set")
	public ResponseBean<Object> set(String key, String value) {
		logger.info("昨晚测试");
		// redisRepository.set(key, value);

		return ResponseBean.success("success");
	}

	@RequestMapping("/get")
	public ResponseBean<Object> get(String key) {

		String result = redisRepository.get(key, String.class);

		return ResponseBean.success(result, result);
	}

	@RequestMapping("/remove")
	public ResponseBean<Object> remove(String key) {

		if (redisRepository.remove(key)){
			return ResponseBean.success("success");
		}
		return ResponseBean.success("fail");
	}

	@RequestMapping("/increment")
	public ResponseBean<Object> increment(String key) {

		return ResponseBean.success(redisRepository.increment(key, 2));
	}

	@RequestMapping("/decrement")
	public ResponseBean<Object> decrement(String key) {

		return ResponseBean.success(redisRepository.decrement(key, 2));
	}
}
